package operation;

import book.BookList;

import java.util.Scanner;

public class DelOperation implements Ioperation{//删除图书
    public void work(BookList bookList){
        for (int i = 0; i < bookList.getNum(); i++) {
            System.out.println(bookList.getBook(i));
        }
        System.out.println("请输入你要删除的书：");
        Scanner ip=new Scanner(System.in);
        while(true){
            String name=ip.nextLine();
            for (int j = 0; j < bookList.getNum()-1 ; j++) {
                if (name.equals(bookList.getBook(j).getName())){
                    int k=0;
                    for (k=j;k<bookList.getNum()-1;k++){
                        bookList.setBooks(k,bookList.getBook(k+1));
                    }
                    System.out.println("删除成功！！");
                    bookList.setNum(-1);
                    break;
                }
                else if (bookList.getNum()-2==j)
                    System.out.println("没有你要删的书");
            }
            System.out.println("请选择：1.继续删书  2.退出");
            int a=ip.nextInt();
            if (a==2)
                break;
        }

    }
}
